package vip.xiaonuo.biz.modular.qhhistory.enums;

import cn.hutool.core.util.StrUtil;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public enum FutureProducts {
    COTTON("CF", "棉花"),  
    SUGAR("SR", "白糖"),  
    PTA("TA", "PTA（精对苯二甲酸）"),  
    METHANOL("MA", "甲醇"),  
    POWER_COAL("ZC", "动力煤"),  
    GLASS("FG", "玻璃"),  
    RAPESEED_OIL("OI", "菜籽油"),  
    RAPE_MEAL("RM", "菜粕"),  
    SILICON_IRON("SF", "硅铁"),  
    MANGANESE_SILICON("SM", "锰硅"),  
    COTTON_YARN("CY", "棉纱"),  
    APPLE("AP", "苹果"),  
    JUJUBE("CJ", "红枣"),  
    UREA("UR", "尿素"),  
    LATE_INDICA_RICE("LR", "晚籼稻"),  
    JAPONICA_RICE("JR", "粳稻"),  
    STRONG_WHEAT("WH", "强麦"),  
    PLAIN_WHEAT("PM", "普麦"),  
    EARLY_INDICA_RICE("RI", "早籼稻"),  
    SODA_ASH("SA", "纯碱"),  
    SHORT_FIBER("PF", "短纤维"),  
    PEANUT("PK", "花生");  
  
    private final String code;  
    private final String name;  
  
    FutureProducts(String code, String name) {  
        this.code = code;  
        this.name = name;  
    }  
  
    public String getCode() {  
        return code;  
    }  
  
    public String getName() {  
        return name;  
    }  
  
    // 你可以添加其他方法，例如根据code查找枚举值等  
    public static FutureProducts findByCode(String code) {  
        for (FutureProducts product : values()) {  
            if (product.getCode().equals(code)) {  
                return product;  
            }  
        }  
        throw new IllegalArgumentException("No matching constant for [" + code + "]");  
    }

    private static final Map<String, String> CACHE = new ConcurrentHashMap<>();
    public static String containsAndGet(String code) {
        String cacheName = CACHE.get(code);
        if (cacheName != null) {
            return cacheName;
        }
        for (FutureProducts product : values()) {
            if (StrUtil.isBlank(code)) {
                break;
            }
            if (code.contains(product.getCode())) {
                CACHE.put(code, product.getName());
                return product.getName();
            }
        }
        throw new IllegalArgumentException("No matching constant for [" + code + "]");
    }
}
